/**
 * com.dingjian.basedata.person.controller.PersonListController.java
 */
package com.dingjian.basedata.person.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.dingjian.base.CoreEntity;
import com.dingjian.base.common.Pagination;
import com.dingjian.base.service.BaseService;
import com.dingjian.basedata.org.model.Org;
import com.dingjian.basedata.org.service.OrgService;
import com.dingjian.basedata.person.model.Person;
import com.dingjian.basedata.person.model.PersonPosition;
import com.dingjian.basedata.person.service.PersonPositionService;
import com.dingjian.basedata.person.service.PersonService;
import com.dingjian.framework.base.controller.TreeListController;

/**
 * @author FengMy
 *
 * @since 2012-10-9
 */
@Controller
@RequestMapping(value="basedata/person/*")
public class PersonListController extends TreeListController {
	@Autowired
	private PersonService personService;
	@Autowired 
	private PersonPositionService personPositionService;
	@Autowired
	private OrgService orgService;
	@Override
	protected String getTreeDataMapper() {
		return "com.dingjian.basedata.org.dao.OrgDao.getChild";
	}

	@Override
	protected CoreEntity createNewEntity() {
		return new Person();
	}

	@Override
	protected String getListView() {
		return "basedata/person/personList";
	}

	@Override
	protected String getEditView() {
		return "basedata/person/personEdit";
	}

	@Override
	protected String getListMapper() {
		return "com.dingjian.basedata.person.dao.PersonDao.getPersonInfoByOrg";
	}
	
	@RequestMapping(value="simpleList")
	public String simpleList(){
		return "basedata/person/simplePersonList";
	}
	
	@RequestMapping(value="simpleListData")
	public void simpleListData(Pagination<Person> pagination,HttpServletResponse response){
		pagination = queryExecutor.execQuery("com.dingjian.basedata.person.dao.PersonDao.select", pagination, getListDataParam());
		outPrint(response, JSONObject.fromObject(pagination, getDefaultJsonConfig()));
	}

	@Override
	protected BaseService<Person> getService() {
		return personService;
	}
	
	@Override
	protected BaseService<Org> getTreeService() {
		return orgService;
	}
	
	@Override
	public String edit(ModelMap model, @RequestParam(required=true,value="id")String id) {
		List<PersonPosition> personPosition = personPositionService.getByPerson(id);
		model.put("personPositions", personPosition);
		return super.edit(model, id);
	}

	@Override
	protected String getSimpleTreeDataMapper() {
		// TODO Auto-generated method stub
		return null;
	}
}
